<!DOCTYPE html>
<html>
<head>
    <title>XHR Example</title>
</head>
<body>
    <p>This example must be run on a server to work properly.</p>
    <script>
    
        function createXHR(){
            if (typeof XMLHttpRequest != "undefined"){
                return new XMLHttpRequest();
            } else if (typeof ActiveXObject != "undefined"){
                if (typeof arguments.callee.activeXString != "string"){
                    var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0",
                                    "MSXML2.XMLHttp"],
                        i, len;
            
                    for (i=0,len=versions.length; i < len; i++){
                        try {
                            new ActiveXObject(versions[i]);
                            arguments.callee.activeXString = versions[i];
                            break;
                        } catch (ex){
                            //skip
                        }
                    }
                }
            
                return new ActiveXObject(arguments.callee.activeXString);
            } else {
                throw new Error("No XHR object available.");
            }
        }
        
        var xhr = createXHR();        
        xhr.open("get", "example.txt", false);
        xhr.send(null);
        
        if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304){
            alert(xhr.statusText);
            alert(xhr.responseText);
        } else {
            alert("Request was unsuccessful: " + xhr.status);
        }
        
    </script>
</body>
</html>
